package edu.put.sk.nrpp;

import java.io.IOException;

import edu.put.sk.nrpp.isis.packet.ISISPacket;
import jpcap.*;
import jpcap.packet.*;

/*

$Rev: 16 $:     Revision of last commit
$Author: marcinwolicki $:  Author of last commit
$Date: 2010-11-21 01:16:40 +0100 (Sun, 21 Nov 2010) $:    Date of last commit
$HeadURL: https://marcinwolicki@network-routing-protocols-presenter.googlecode.com/svn/trunk/nrpp/src/edu/put/sk/Network.java $:
$Id: Network.java 16 2010-11-21 00:16:40Z marcinwolicki $:

*/

public class NetworkISIS extends Network implements PacketReceiver {
	
	@Override
	protected void protocolMachine(){
		System.out.println("isis");
		NetworkInterface[] devices = JpcapCaptor.getDeviceList();

		final JpcapCaptor jpcap;
		try {
			jpcap = JpcapCaptor.openDevice(devices[1], 2000, false, 20);
			
			jpcap.loopPacket(-1, this);
			System.out.println("END ISIS");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	@Override
	public void receivePacket(Packet p) {
		Bit[] data=Bit.parseByte(p.data);
		Bit[] header=Bit.parseByte(p.header);
		int destAddress=Bit.toInt(Bit.cut(header, 0, 47));
		if(destAddress==-1040187374||destAddress==-1040187375){
			try {
				System.out.println(p);
				ISISPacket.getInstance(header, data);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		
	}

}
